package com.localjoycommunity.cpdj.project.system.controller;

import com.localjoycommunity.cpdj.common.R;
import com.localjoycommunity.cpdj.common.interceptor.help.NeedLogin;
import com.localjoycommunity.cpdj.common.utils.poi.ExcelUtil;
import com.localjoycommunity.cpdj.framework.aspectj.lang.annotation.Log;
import com.localjoycommunity.cpdj.framework.aspectj.lang.enums.BusinessType;
import com.localjoycommunity.cpdj.framework.web.controller.BaseController;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import com.localjoycommunity.cpdj.framework.web.page.TableDataInfo;
import com.localjoycommunity.cpdj.project.system.domain.WishList;
import com.localjoycommunity.cpdj.project.system.domain.vo.UserWishListVo;
import com.localjoycommunity.cpdj.project.system.service.IWishListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 心愿列Controller
 *
 * @author aqie
 * @date 2020-11-29
 */
@RestController
@RequestMapping("/system/wishlist")
public class WishListController extends BaseController
{
    @Autowired
    private IWishListService wishListService;

    /**
     * 查询心愿列列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WishList wishList)
    {
        startPage();
        List<WishList> list = wishListService.selectWishListList(wishList);
        return getDataTable(list);
    }

    /**
     * 查询用户心愿列表
     */
    @GetMapping("user/{bool}")
    @NeedLogin
    public R<List<UserWishListVo>> userWishList(HttpServletRequest req,@PathVariable("bool") Integer bool){
        Integer userId = getUserId(req);
        return R.success(wishListService.userWishList(userId,bool));
    }

    /**
     * 导出心愿列列表
     */
    @Log(title = "心愿列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WishList wishList)
    {
        List<WishList> list = wishListService.selectWishListList(wishList);
        ExcelUtil<WishList> util = new ExcelUtil<WishList>(WishList.class);
        return util.exportExcel(list, "wishlist");
    }

    /**
     * 获取心愿列详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wishListService.selectWishListById(id));
    }

    /**
     * 新增心愿列
     */
    @Log(title = "心愿列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WishList wishList)
    {
        return toAjax(wishListService.insertWishList(wishList));
    }

    /**
     * 修改心愿列
     */
    @Log(title = "心愿列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WishList wishList)
    {
        return toAjax(wishListService.updateWishList(wishList));
    }

    /**
     * 删除心愿列
     */
    @Log(title = "心愿列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wishListService.deleteWishListByIds(ids));
    }
}
